<%-- 
    Document   : DeleteUserArt
    Created on : 24-mag-2010, 10.12.55
    Author     : giuseppebrusadin
--%>
<%@taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.sql.Connection" %>
<%@page import="java.sql.PreparedStatement" %>
<%@page import="java.sql.ResultSet" %>
<%@page import="altri.database" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" type="text/css" href="CSSHome.css" media="all">
        <title>Cancella Articoli</title>
    </head>
    <body>
        <%
                    HttpSession hs = request.getSession(false);

                    if (hs.getAttribute("login") == null) {
        %> <jsp:forward page="login.jsp" /> <%                           }
                    if (!(Boolean) hs.getAttribute("login")) {
        %> <jsp:forward page="login.jsp" /> <%                            }
                   
                    Connection conn = database.connessione();
                    if (conn == null) {
                     hs.setAttribute("database", false);
        %> <jsp:forward page="/WEB-INF/Error.jsp" /> <%                             }

                    PreparedStatement psCat = conn.prepareStatement("SELECT id,Nome,Categoria FROM Categorie ORDER BY id, Categoria ", ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
                    ResultSet rsCat = psCat.executeQuery();


        %>

        <img id="top" src="img/top.png" alt="">
        <div id="logo">
            <div id="menu">
            <ul>
                <li><a href="index.jsp" >Home</a>
            </ul>
        </div>
        </div>
        <div id="contenitore">
            <div id="contenitore_articoli">
                <h2>Cancella articoli</h2>
                
                <%  PreparedStatement psArt;
                        if ((Boolean)hs.getAttribute("isAdmin")){
                                 psArt = conn.prepareStatement("SELECT Id,Titolo FROM Articoli", ResultSet.TYPE_SCROLL_INSENSITIVE,
                                    ResultSet.CONCUR_READ_ONLY);
                            }else{
                             psArt = conn.prepareStatement("SELECT Id,Titolo FROM Articoli WHERE Nick = ?", ResultSet.TYPE_SCROLL_INSENSITIVE,
                                    ResultSet.CONCUR_READ_ONLY);
                            psArt.setString(1, (String) hs.getAttribute("Nickname"));
                            }
                            ResultSet rsArt = psArt.executeQuery();

                            while (rsArt.next()) {
                                out.println("<div class=articolo><b>"+rsArt.getString("Titolo")+"</b>");

                %>
                <form action="cancellaArt.do" method="POST">
                    <input type="hidden" name="id" value=<%=rsArt.getInt("Id")%> />
                    <input type="submit" value="Cancella" />
                </form>
                <%          out.print("</div>");
                            }
                            rsArt.close();
                %>
            </div>
            <div id="col_destra">
                <%
                            PreparedStatement ps = conn.prepareStatement("SELECT id,Nome,Categoria FROM Categorie ORDER BY id, Categoria ",
                                    ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
                            ResultSet rs = ps.executeQuery();
                %>
                <div id="ricerca">
                    <h2>Ricerca</h2>
                    <form action="ricercaArticoli.do" method="POST">
                        <div id="box_cat">
                            <select name="categorie" Id="categorie">
                                <%
                                            while (rs.next()) {
                                %>
                                <option value="<%=rs.getString("id")%>"><%=rs.getString("Nome")%></option>
                                <%
                                            }
                                %>
                            </select><br/>
                            <%
                                PreparedStatement psAttr = conn.prepareStatement("SELECT * FROM Attributi",
                                    ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
                            ResultSet rsAttr = psAttr.executeQuery();

                              while (rsAttr.next()){

                                 String nome = rsAttr.getString("Nome");
                                 String tipo = rsAttr.getString("Tipo");

                                        if (tipo.equalsIgnoreCase("Booleano")) {%>
                    <%=nome%>:<input type="checkbox" name="<%=nome %>" /><br>
                    <%
                                   }
                                   if (tipo.equalsIgnoreCase("Intero")) {
                    %>
                  <label><%=nome%>:</label><input type="text" name="<%=nome%>" />  <br>
                    <% }
                                   if (tipo.equalsIgnoreCase("Stringa")) {
                    %>
                    <label><%=nome%>:</label><input type="text" name="<%=nome%>" value=""/> <br>
                    <% }
                                   if (tipo.equalsIgnoreCase("Time")) {
                    %>
                    <label><%=nome%>:</label>
                    <input type="hidden" name="<%=nome %>" value="<%=nome %>" />
                    Giorno: <select name="<%=nome%>Giorno">
                        <option value="">---</option>
                        <% for (int j=1;j<32;j++){ %>
                        <option value="<%=j %>"><%=j %> </option>
                        <%  } %>
                    </select>
                    Mese: <select name="<%=nome%>Mese">
                        <option value="">---</option>
                        <% for (int j=1;j<13;j++){ %>
                        <option value="<%=j %>"><%=j %> </option>
                        <%  } %>
                    </select>
                    Anno: <select name="<%=nome%>Anno">
                        <option value="">---</option>
                        <% for (int j=2000;j<2021;j++){ %>
                        <option value="<%=j %>"><%=j %> </option>
                        <%  } %>
                    </select>
                    <br>
                    <% }


                              }
                            %>
                        </div>
                        <div id="submit">
                            <input type="submit" value="Cerca" />
                        </div>
                    </form>
                </div>
                <%
                            rsCat.close();
                            psCat.close();
                            conn.close();
                            Object login = hs.getAttribute("login");
                            if ((login != null && (Boolean) login)) {
                %>
                <div id="dati_personali">
                    <h2>Benvenuto "<%= ((String) session.getAttribute("Nickname")).toString()%>"!</h2>
                    <div class="link_centrale"><a href="logout.do">Logout</a></div>
                </div>
                <div id="menuDestro">
                    <ul>
                        <li><strong><a href="index.jsp" >Home page</a></strong></li>
                        <li><a href="ModificaUserArt.jsp">Visualizza e modifica i tuoi articolo</a></li>
                        <li><a href="nuovo_articolo.jsp">Inserisci articolo</a></li>
                        <li><a href="DeleteUserArt.jsp">Elimina articolo</a></li>
                        <% if ((Boolean) hs.getAttribute("isAdmin")) {%>
                        <li><a href="RiepilogoAttributi.jsp">Gestione attributi</a></li>
                        <li><a href="InsertAttributi.jsp">Inserimento attributi</a></li>
                        <li><a href="InsertCategory.jsp">Inserisci categoria</a></li>
                        <li><a href="RiepilogoCategorie.jsp">Riepilogo categorie</a></li>
                        <%}%>
                    </ul>
                </div>
                <% }%>

            </div>
        </div>
        <img id="bottom" src="img/bottom.png" alt="" />
    </body>
</html>

